<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>图片信息管理</title>
<script type="text/javascript">
	var url;
	//打开新增患者对话框
	function openPatientAddDialog() {
		//在勾选情况下点击新增要先清除数据
		resetValue();
		$("#dlg").dialog("open").dialog("setTitle", "添加图片信息");
		url = "${pageContext.request.contextPath}/city/save.do";//为url赋值
	}
	//重置对话框内数据
	function resetValue() {
		$("#name").val("");
		$("#province").combobox("setValue", "");
	}
	//关闭对话框
	function closePatientDialog() {
		$("#dlg").dialog("close");
		resetValue();
	}
	//提交新增患者数据
	function savePatient() {

		$("#fm").form("submit", {
			url : url,
			onSubmit : function() {
				if ($('#name').val() == "") {
					$.messager.alert("系统提示", "名字不能为空");
					return false;
				}

				return $(this).form("validate");
			},
			success : function(result) {
				if (result.errorMsg) {
					$.messager.alert("系统提示", result.errorMsg);
					return;
				} else {
					$.messager.alert("系统提示", "保存成功");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}
			}
		});
	}
	//删除选中的患者数据
	function deletePatient() {
		//获得选中数据对象
		var selectedRows = $("#dg").datagrid('getSelections');
		if (selectedRows.length == 0) {
			$.messager.alert("系统提示", "请选择要删除的数据！");
			return;
		}
		var strIds = [];//要删除的序号组合
		for (var i = 0; i < selectedRows.length; i++) {
			strIds.push(selectedRows[i].id);
		}
		var ids = strIds.join(",");
		$.messager.confirm("系统提示", "您确认要删掉这<font color=red>"
				+ selectedRows.length + "</font>条数据吗？", function(r) {
			if (r) {
				//ajax提交 delIds
				$.post("${pageContext.request.contextPath}/city/delete.do", {
					ids : ids
				}, function(result) {
					if (result.success) {
						$.messager.alert("系统提示", "您已成功删除<font color=red>"
								+ result.delNums + "</font>条数据！");
						$("#dg").datagrid("reload");
					} else {
						$.messager.alert('系统提示', result.errorMsg);
					}
				}, "json");
			}
		});
	}
	//修改患者资料
	function openPatientModifyDialog() {
		var selectedRows = $("#dg").datagrid('getSelections');
		if (selectedRows.length != 1) {
			$.messager.alert("系统提示", "请选择一条要编辑的数据！");
			return;
		}
		var row = selectedRows[0];
		url = "${pageContext.request.contextPath}/city/save.do?id=" + row.id;
		$("#dlg").dialog("open").dialog("setTitle", "编辑资料");
		$("#name").val(row.name);
		$("#province").combobox("setValue", row.province.name);
	}
	//查询符合条件的用户
	function searchPatient() {
		$('#dg').datagrid('load', {
			sname : $('#sname').val(),
		});
	}
	//倒出excel数据
	function exportPatient() {
		$('#export').form("submit", {
			url : "${pageContext.request.contextPath}/city/excel.do"
		})
	}
</script>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/admin/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/admin/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/admin/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/admin/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/admin/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin: 5px">
	<table id="dg" title="图片信息" class="easyui-datagrid" fitColumns="true"
		pagination="true" rownumbers="true"
		url="${pageContext.request.contextPath}/city/list" fit="true"
		toolbar="#tb">
		<thead>
			<tr>
				<th field="cb" checkbox="true">编号</th>
				<th field="id" width="30" align="center" hidden="true">id</th>
				<th field="name" width="30" align="center">名字</th>
				<th field="province" width="30" align="center" data-options="formatter:function(province){
           				 if(province.name){
                     return province.name;}}">所属省</th>
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:openPatientAddDialog()" class="easyui-linkbutton"
				iconCls="icon-add" plain="true">添加</a> <a
				href="javascript:openPatientModifyDialog()"
				class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a> <a
				href="javascript:deletePatient()" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true">删除</a> <a
				href="javascript:exportPatient()" class="easyui-linkbutton"
				iconCls="icon-export" plain="true">导出Execl</a>
		</div>
		<div>
			<form id="export" method="post">
				&nbsp;名字：&nbsp;<input type="text" name="sname" id="sname" size="10" />
				<a href="javascript:searchPatient()" class="easyui-linkbutton"
					iconCls="icon-search" plain="true">搜索</a>
			</form>
		</div>
	</div>

	<div id="dlg" class="easyui-dialog"
		style="width: 570px; height: 340px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons">
		<form id="fm" method="post" enctype="multipart/form-data">
			<table cellspacing="5px;">
				<tr>
					<td>名字：</td>
					<td><input type="text" name="name" id="name"
						class="easyui-validatebox" /></td>
					<td>所属省：</td>
					<td><input class="easyui-combobox" name="pid"
						id="province" style="width: 148px"
						data-options="editable:false,panelHeight:200,valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/province/provinceAll'" /></td>
				</tr>
			</table>
		</form>
	</div>

	<div id="dlg-buttons">
		<a href="javascript:savePatient()" class="easyui-linkbutton"
			iconCls="icon-ok">保存</a> <a href="javascript:closePatientDialog()"
			class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
</body>
</html>